package com.hnevc.mytrafficdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.hnevc.mytrafficdemo.R;
import com.hnevc.mytrafficdemo.fragment.BoundFragment;
import com.hnevc.mytrafficdemo.fragment.PersonMessageFragment;
import com.hnevc.mytrafficdemo.fragment.RechargeRecordFragment;

import java.util.ArrayList;
import java.util.List;

public class PersonCenterActivity extends AppCompatActivity {
    ViewPager mViewPager;
    List<Fragment> mFragmentList;

    TextView mTvPersonMsg ;
    TextView mTvRechargeRecord;
    TextView mTvBoundSetting;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_center);

        Intent intent = getIntent();
        mTvPersonMsg = (TextView) findViewById(R.id.id_tv_person_center_message);
        mTvRechargeRecord = (TextView) findViewById(R.id.id_tv_person_center_rechargerecord);
        mTvBoundSetting = (TextView) findViewById(R.id.id_tv_person_center_chargeBound);

        mFragmentList = new ArrayList<>();
        PersonMessageFragment fragment1 = new PersonMessageFragment();
        RechargeRecordFragment fragment2 = new RechargeRecordFragment();
        BoundFragment fragment3 = new BoundFragment();

        mFragmentList.add(fragment1);
        mFragmentList.add(fragment2);
        mFragmentList.add(fragment3);

        mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
        MyFragmentAdapter adapter = new MyFragmentAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);

        mTvPersonMsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mViewPager.setCurrentItem(0);
            }
        });
        mTvRechargeRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mViewPager.setCurrentItem(1);
            }
        });
        mTvBoundSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mViewPager.setCurrentItem(2);
            }
        });


    }

    class MyFragmentAdapter extends FragmentPagerAdapter{

        public MyFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    }
}
